Option Explicit

Dim obBaseApp
Dim objFSO
Dim objTextFile
Dim strNewUser,i

Const ForReading = 1

Set obBaseApp = CreateObject("hMailServer.Application")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("Users.csv", ForReading)

Do While objTextFile.AtEndOfStream <> True
    strNewUser = split(objTextFile.Readline, ",")
    AddUser strNewUser(0), strNewUser(1), strNewUser(2)
    i = i + 1
Loop

Sub AddUser(strUsername, strPassword, strDomain)
   Dim obDomain
   Dim obAccounts
   Dim obNewAccount

   Set obDomain = obBaseApp.Domains.ItemByName(strDomain)
   Set obAccounts = obDomain.Accounts
   Set obNewAccount = obAccounts.Add()
   
   obNewAccount.Address = strUsername & "@" & strDomain 'username
   obNewAccount.Password = strPassword 'password
   obNewAccount.Active = 1 'activates user
   obNewAccount.Maxsize = 0 'sets mailbox size, 0=unlimited
   obNewAccount.Save() 'saves account
   
   Set obNewAccount = Nothing
   Set obDomain = Nothing   
   Set obAccounts = Nothing
   
End Sub